﻿@{
    ViewBag.Title = "TimeClassInfo";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>         
}

<form id="form1" method="post">
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" name="SaveInfo" iconCls="icon-save" onclick="SaveInfo" plain="true">保存</a>
                        <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                    </td>
                </tr>
            </table>                
        </div>    
        <div name="Base" title="会员分类" style="height:100%;overflow:hidden;margin-top:5px;margin-left:20px">
            <table>
                <tr>
                    <td width="80px" height ="35px" align="right">会员分类：</td>
                    <td width="240px" height ="35px">
                        @Html.Partial("~/Views/Modular/LookupMembersClass.cshtml")
                    </td>
                    <td width="80px" height ="35px" align="right">使用期限：</td>
                    <td width="240px" height ="35px" colspan="2">
                        <input id="FCardType" name="FCardType" class="mini-combobox" style="width:240px;" TabIndex="5" value ="1" data ="CardType" onvaluechanged="TypeChange"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">门店选择：</td>
                    <td width="200px" height ="35px">
                        @Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")
                    </td>
                    <td width="80px" height ="35px" align="right">
                        <div id="typeName">有效天数：</div></td>
                    <td width="240px" height ="35px" colspan="2">
                        <div id="type2" style="display:none;">
                            <table align="left" style="width:240px; left: -3px">
                                 <tr>
                                    <td width ="110px">
                                        <input class="mini-datepicker" name="FDate1" format="yyyy-MM-dd" style="width:110px;" value = ""/></td>
                                    <td width ="16px">至</td>
                                    <td width ="110px">
                                        <input class="mini-datepicker" name="FDate2" format="yyyy-MM-dd" style="width:110px;" value = ""/></td>
                                 </tr>
                            </table>
                        </div>
                        <div id="type1">
                            <input id="FEffectDays" name="FEffectDays" class="mini-spinner" minValue="0" maxValue="9999" changeOnMousewheel ="false" 
                                 style="width:240px;" TabIndex="7" showbutton="false"  format="#,0" value="1"/>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">项目编码：</td>
                    <td width="200px" height ="35px">
                        <input name="FNumber" id="FNumber" class="mini-textbox" style="width:200px;"  value="" TabIndex="2"/>
                    </td>
                    <td width="80px" height ="35px" align="right">销售价格：</td>
                    <td width="240px" height ="35px" colspan="2">
                        <input id="FAmount" name="FAmount" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel ="false" 
                             style="width:240px;" TabIndex="6" showbutton="false"  format="#,0.00" value="0"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">项目名称：</td>
                    <td width="200px" height ="35px">
                        <input id="FName" name="FName" class="mini-textbox " style="width:200px;" TabIndex="3"/>
                    </td>
                    <td width="80px" height ="35px" align="right">会员折扣：</td>
                    <td width="240px" height ="35px" colspan="2">
                        <input id="FDiscount" name="FDiscount" class="mini-spinner" minValue="0" maxValue="1" changeOnMousewheel ="false" 
                            style="width:240px;" TabIndex="7" showbutton="false"  format="#,0.00" value="0"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">充值金额：</td>
                    <td width="200px" height ="35px">
                        <input id="FDepositAmt" name="FDepositAmt" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel ="false" 
                             style="width:200px;" TabIndex="6" showbutton="false" format="#,0.00" value="0"/>
                    </td>
                   <td width="80px" height ="35px" align="right">项目状态：</td>
                    <td width="240px" height ="35px">
                        <input id="FState" name="FState" class="mini-combobox" style="width:240px;" TabIndex="9" value="0" data="FStateData" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right">会员积分：</td>
                    <td width="200px" height ="35px">
                        <input id="FIntegral" name="FIntegral" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel ="false" 
                             style="width:200px;" TabIndex="6" showbutton="false"  value="0"/>
                    </td>
                    <td width="80px" height ="35px" align="right">提成金额：</td>
                    <td width="240px" height ="35px">
                        <input id="FRebateValue" name="FRebateValue" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false"
                               style="width:240px;" TabIndex="6" showbutton="false" value="0" format="#,0.00"/>
                    </td>
                </tr>
                <tr>
                    <td width="80px" height ="35px" align="right"><span id="RebateTip">备注：</span></td>
                    <td width="200px" height ="35px">
                        <input id="FRemark" name="FRemark" class="mini-textbox " style="width:200px;" TabIndex="10" />
                    </td>
                    <td width="80px" height ="35px" align="right"></td>
                    <td width="240px" height ="35px">
                        <div id="ck1" name="ck1"  class="mini-checkbox" style ="margin-right:70px" readOnly="false" value ="true" text="连续新增 "></div>
                    </td>
                </tr>
            </table>
        </div>
    <input name="FItemID" class="mini-hidden" />
    <input name="FClassID" class="mini-hidden" />
</form>
<script>
    var CardType = [{ "id": "0", "text": "不限制" },
                       { "id": "1", "text": "限制使用天数" },
                    { "id": "2", "text": "固定使用日期" }];
    var FStateData = [{ "id": "0", "text": "正常" },
                        { "id": "1", "text": "停用" }];

    mini.parse();
    function FormShown() {
        var nowDate = new Date();
        mini.getbyName("FDate1").setValue(nowDate);
        mini.getbyName("FDate2").setValue(nowDate);
    }

    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            mini.getbyName("FMembersClassID").setValue(data.FClassID);
            mini.getbyName("FMembersClassID").setText(data.FClassNumber);
            mini.getbyName("FMembersClassName").setValue(data.FClassName);
            NewInfo();
        }
        else {
            $.post("GetServiceInfo", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
                mini.getbyName("FMembersClassID").setText(mdata.data[0].FMemberClassNumber);
                mini.getbyName("FMembersClassID").setValue(mdata.data[0].FMemberClassID);
                mini.getbyName("FMembersClassName").setValue(mdata.data[0].FMemberClassName);
                mini.getbyName("FStockID").setText(mdata.data[0].FStockNumber);
                mini.getbyName("FStockID").setValue(mdata.data[0].FStockID);
                mini.getbyName("FNumber").setEnabled(false);
                mini.getbyName("FDate1").setValue(mdata.data[0].FStartDate);
                mini.getbyName("FDate2").setValue(mdata.data[0].FEndDate);
                mini.getbyName("FState").setValue(mdata.data[0].FState);
                setType(mdata.data[0].FCardType);
                mini.getbyName("ck1").setChecked(false);
                mini.getbyName("FIntegral").setValue(mdata.data[0].FIntegral);
                mini.getbyName("FRebateValue").setValue(mdata.data[0].FRebateValue);
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FAmount").setValue("0");
        mini.getbyName("FEffectDays").setValue("0");
        mini.getbyName("FDiscount").setValue("0");
        mini.getbyName("FRemark").setValue("");
        mini.getbyName("FRebateValue").setValue(0);
        var jsonstr = '{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}';
        $.post('NewServiceInfo', { json: jsonstr }, function (data) {
            mini.getbyName("FNumber").setValue(data);
        });

        $.post("DefaultMTStock", { json: '[{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]' }, function (data) {
            var mdata = mini.decode(data);
            if (mdata.data.length > 0) {
                mini.getbyName("FStockID").setText(mdata.data[0].FNumber);
                mini.getbyName("FStockID").setValue(mdata.data[0].FItemID);
                mini.getbyName("FStockName").setValue(mdata.data[0].FName);
            }
        });
    }

    //保存资料
    function SaveInfo() {
        mini.getbyName("SaveInfo").setEnabled(false);
        if (mini.getbyName("FCardType").getValue() == 0) {
            var nowDate = new Date();
            nowDate.setFullYear(1900, 01, 01);
            mini.getbyName("FDate1").setValue(nowDate);
            nowDate.setFullYear(2099, 12, 31);
            mini.getbyName("FDate2").setValue(nowDate);
        }
        if (mini.getbyName("FCardType").getValue() != 1) {
            mini.getbyName("FEffectDays").setValue(0);
        }
        var form = new mini.Form("#form1");
        var data = form.getData(true, false);
        if (!validata(data)) {
            mini.getbyName("SaveInfo").setEnabled(true);
            return;
        }
        var json = mini.encode(data);
        $.post("SaveServiceInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                if (mini.getbyName("ck1").getChecked() == false)
                    CloseWindow();
                else
                    NewInfo();
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }

    function validata(data) {
        if (data.FStockID == '') {
            mini.alert("门店未选择");
            return false;
        }
        if (data.FMembersClassID == '') {
            mini.alert("会员分类未选择");
            return false;
        }
        if (data.Fnumber == '') {
            mini.alert("项目编号未输入");
            return false;
        }
        if (data.FName == '') {
            mini.alert("项目名称不能为空");
            return false;
        }
        if (data.FAmount == '') {
            mini.alert("消费金额未输入");
            return false;
        }
        if (data.FEffectDays == '') {
            mini.alert("有效天数未输入");
            return false;
        }
        if (data.FDiscount == '') {
            mini.alert("会员折扣未输入");
            return false;
        }
        return true;
    }

    function TypeChange() {
        setType(mini.getbyName("FCardType").getValue());
    }

    function setType(typeValue){
        if (typeValue == 0) {
            $("#typeName").html("有效天数：");
            $("#type1").show();
            mini.getbyName("FEffectDays").setEnabled(false);
            mini.getbyName("FEffectDays").setValue(0);
            $("#type2").hide();
        }
        else if (typeValue == 1) {
            $("#typeName").html("有效天数：");
            $("#type1").show();
            mini.getbyName("FEffectDays").setEnabled(true);
            $("#type2").hide();
        }
        else if (typeValue == 2) {
            $("#typeName").html("固定日期：");
            $("#type1").hide();
            $("#type2").show();
        }
    }
</script>
